package com.niit.servlet;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.niit.domain.News;
import com.niit.domain.Product;
import com.niit.service.INewsService;
import com.niit.service.IProductService;
import com.niit.service.impl.NewsServiceImpl;
import com.niit.service.impl.ProductServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "NewsByIDServlet", value = "/NewsByIDServlet")
public class NewsByIDServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String idStr = request.getParameter("nid");
        Integer id = Integer.parseInt(idStr);
        INewsService iNewsService = new NewsServiceImpl();
        News news = iNewsService.queryNewsByIDService(id);
        ObjectMapper mapper = new ObjectMapper();
        response.setContentType("application/json;charset=utf-8");
        mapper.writeValue(response.getOutputStream(),news);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
